﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FluentResourceMapping.AutoMapping
{
    public class SameMemberNameResourceMappingConvention : DefaultMemberResourceMappingConvention
    {
        public override System.Reflection.MemberInfo MapsTo(System.Reflection.MemberInfo property)
        {
            Type mappedType = ResourceTypes.SingleOrDefault(o => o.Name == property.DeclaringType.Name);

            if (mappedType == null)
                return null;

            System.Reflection.MemberInfo mappedMember =
                mappedType.GetMembers().SingleOrDefault(m => m.Name == property.Name);

            if (mappedMember == null)
                return null;

            return mappedMember;
        }
    }
}